<template>
	<view class="container">
		<view class="mode-box">
			<view class="mode-title">模式选择</view>
			<view class="mode-item-box">
				<view @tap="selectMode" class="mode-item" data-index="1" :class="{'mode-item-a': modeIndex == 1}">普招</view>
				<view @tap="selectMode" class="mode-item" data-index="2" :class="{'mode-item-a': modeIndex == 2}">单招</view>
			</view>
			<view class="mode-item-box-art">
				<view @tap="selectMode" class="mode-item" data-index="3" :class="{'mode-item-a': modeIndex == 3}">艺术生</view>
			</view>
			<view class="tips">*高考后可再修改一次</view>
		</view>
		<view class="section-box">
			<view class="section-title">分数段选择</view>
			<view class="section-item-box">
				<view @tap="selectSection(index)" class="section-item" :class="{'section-item-a': item.isSelected}" v-for="(item,index) in sectionList" :key="item.id">
					<view v-if="item.low < 550">{{item.low}}~{{item.high}}</view>
					<view v-else>{{item.low}}以上</view>
				</view>
			</view>
			<view class="section-tips">*只可选择一个或两个相邻分数区间</view>
		</view>
		<view class="submit-btn-box">
			<view class="submit-btn">确认</view>
		</view>
	</view>
</template>

<script>
	import { http, showToastMsg } from '../../utils'
	
	export default {
		data() {
			return {
				modeIndex: 0,
				sectionList: [
					{id: 1, low: 0, high: 200, isSelected: false},
					{id: 2, low: 200, high: 240, isSelected: false},
					{id: 3, low: 240, high: 300, isSelected: false},
					{id: 4, low: 300, high: 360, isSelected: false},
					{id: 5, low: 360, high: 400, isSelected: false},
					{id: 6, low: 400, high: 460, isSelected: false},
					{id: 7, low: 460, high: 500, isSelected: false},
					{id: 8, low: 500, high: 550, isSelected: false},
					{id: 9, low: 550, high: 750, isSelected: false}
				],
				sectionMap: new Set()
			}
		},
		
		methods: {
			
			selectMode(e) {
				this.modeIndex = e.currentTarget.dataset.index
			},
			
			selectSection(index) {
				const that = this
				let size = that.sectionMap.size
				let isSelected = !that.sectionList[index].isSelected
				if (isSelected) {
					if (size == 1) {
						let arr = [...that.sectionMap]
						let abs = Math.abs(arr[0] - index)
						if (abs != 1) {
							return showToastMsg('选择的两个区间必须是相邻的')
						}
					} else if (size >= 2) {
						return showToastMsg('最多选择两个分数区间')
					}
					that.sectionMap.add(index)
				} else {
					that.sectionMap.delete(index)
				}
				that.sectionList[index].isSelected = isSelected
			}
			
		}
	}
</script>

<style>
	.container {
		width: 750rpx;
	}
	
	.tips {
		width: 620rpx;
		color: #999999;
		font-size: 24rpx;
		margin-top: 20rpx;
	}
	
	.section-tips {
		width: 620rpx;
		color: #999999;
		font-size: 24rpx;
		margin-top: -30rpx;
	}
	
	.mode-box {
		width: 750rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 36rpx;
	}
	
	.mode-title {
		width: 600rpx;
		font-size: 30rpx;
		color: #333333;
	}
	
	.mode-item-box {
		width: 640rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		margin-top: 30rpx;
	}
	
	.mode-item-box-art {
		width: 640rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		margin-top: 50rpx;
	}
	
	.mode-item {
		width: 300rpx;
		height: 86rpx;
		background-color: #f8f8f8;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		font-size: 30rpx;
		color: #666666;
	}
	
	.mode-item-a {
		color: #45d6b7;
		background-color: #a9f4e4;
	}
	
	.section-box {
		width: 750rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 90rpx;
	}
	
	.section-title {
		width: 600rpx;
		font-size: 30rpx;
		color: #333333;
	}
	
	.section-item-box {
		width: 640rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		flex-wrap: wrap;
		margin-top: 30rpx;
	}
	
	.section-item {
		width: 300rpx;
		height: 86rpx;
		background-color: #f8f8f8;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		font-size: 30rpx;
		color: #666666;
		margin-bottom: 50rpx;
	}
	
	.section-item-a {
		color: #45d6b7;
		background-color: #a9f4e4;
	}
	
	.submit-btn-box {
		width: 750rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 56rpx;
	}
	
	.submit-btn {
		width: 556rpx;
		height: 92rpx;
		background-color: #45d6b7;
		border-radius: 46rpx;
		font-size: 36rpx;
		color: #ffffff;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
</style>
